﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    public class SymptomAll : BasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<TopicInfo> TopicDataListHottest;
        protected List<TopicInfo> TopicDataListLatest;
        protected List<UserInfo> UserDataListLatest;

        // 和当前登录用户症状最接近的病友
        protected List<UserInfo> bestFitPatientsBySymptoms;

        // 当前登录用户所患疾病的高发症状
        protected string diseaseName = string.Empty;
        protected List<SymptomAndIncidenceCount> highIncidenceSymptomsOfDisease;

        protected List<SymptomInfo> SymptomDataList;
        protected List<DiseaseInfo> DiseaseLst;
        protected int SymptomCount = 0;
        protected int SymptomPageCount = 0;
        protected int SymptomPageSize = 15;
        protected int SymptomPageIndex = 1;
        protected string SymptomPagingString;

        protected void HandleCommon()
        {
            this.AddLocation("症状列表", "/SymptomAll.aspx");
            DiseaseLst = DiseaseBLL.Instance.GetAllDiseaseByName("");
        }

        protected void HandlePost()
        {

        }

        protected void HandleGet()
        {
            int topiccnt = 8;
            TopicDataListHottest = TopicBLL.Instance.GetHottestTopic(topiccnt);
            TopicDataListLatest = TopicBLL.Instance.GetLastestTopic(topiccnt);

            // 如果用户已经登录，获取和当前登录用户症状最接近的病友列表
            if (UserData.Id > 0)
            {
                PatientRecordInfo prInfo = PatientBLL.Instance.GetPatientRecordInfo(UserData.Id);
                if (prInfo.DiseaseId > 0)
                {
                    UserData.DiseaseId = prInfo.DiseaseId;

                    bestFitPatientsBySymptoms = PatientBLL.Instance.GetBestFitSymptomsPatientList(prInfo.Id);

                    if (bestFitPatientsBySymptoms != null && bestFitPatientsBySymptoms.Count > 4)
                        bestFitPatientsBySymptoms = bestFitPatientsBySymptoms.GetRange(0, 4);

                    // 获得当前登录用户所患疾病的高发症状
                    highIncidenceSymptomsOfDisease = 
                        DiseaseBLL.Instance.GetHighIncidenceSymptomsOfDisease(prInfo.DiseaseId, 4);

                    diseaseName = DiseaseBLL.Instance.GetDiseaseInfo(prInfo.DiseaseId).Name;
                }

            }
            

            SymptomSearchConditon cond = new SymptomSearchConditon();
            cond.DiseaseId = RequestTools.GetInt("dszid", 0);
            cond.DiseaseName = RequestTools.GetString("dszname");
            cond.SymptomName = RequestTools.GetString("symname");

            SymptomPageIndex = RequestTools.GetQueryInt("page", 1);

            SymptomDataList = SymptomBLL.Instance.GetSymptomList(
                SymptomPageSize,SymptomPageIndex,
                cond, out SymptomCount);

            SymptomPageCount = Utils.GetPageCount(SymptomCount, SymptomPageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            SymptomPagingString = this.GetPagingString(
                SymptomPageIndex,
                SymptomPageCount,
                "/SymptomAll.aspx" + query, "page");
        }   

    }
}